import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import fire_component_msg from '@feidao/web/atom/browser/fsm/fire-component-msg';
import upload from '../atom/upload';

export default async function a003(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	//  上传
	const f = fd.data.node.querySelector<HTMLFormElement>('#certifi_info_form');
	const accessory_url = f.accessory_url.value;
	if (!accessory_url) {
		fire_component_msg('zj-common-002', 'ec-001', 'fail', '请选择要上传的文件');
	} else {
		const accessory_id = fd.data.accessory_id;
		const res: any = await upload(fd, accessory_id, f.accessory_url);
		if (res == 'fail') {
			fire_component_msg('zj-common-002', 'ec-001', 'fail', '上传失败');
		} else if (res.filename) {
			fd.data.accessory_url = res.filename;
			fire_component_msg('zj-common-002', 'ec-001', 'success', '上传成功');
		} else {
			fire_component_msg('zj-common-002', 'ec-001', 'fail', '上传失败');
		}
	}
}
